<template>
	<view>
		<view class="line1 mb10">
			<view
				><text class="fw500"
					>{{ weekStr }} {{ dateStr }} {{ startTime }}-{{
						endTime
					}}</text
				></view
			>
			<view class="detail-btn" @click="checkDetail"
				><text class="g89">查看详情</text></view
			>
		</view>
		<view class="mb10"
			><text>{{ name }}</text></view
		>
		<view class="mb10">
			<text class="a9">会议号：{{ meetingCodeSpace }}</text>
			<text class="g89 ml10" @click="copy">复制</text>
		</view>
		<view class="mb10">
			<text class="a9"
				>发起人：{{ createName
				}}{{ createIsSelf ? '（本人）' : '' }}</text
			>
		</view>
		<view class="mb10">
			<text class="a9" v-if="createIsSelf"
				>参与人：{{ totalNum }}人<text class="a3 accept-text">
					{{ agreeNum }}</text
				>人接受/<text class="reject-color">{{ refuseNum }}</text
				>人拒绝</text
			>

			<text class="a9" v-else>参与人：{{ totalNum }}人</text>
		</view>
		<view class="line-box mb20"></view>
		<view>
			<view class="mb20">
				<button class="enter-button plain" @click="joinMeeting">
					进入会议
				</button>
			</view>
			<view v-if="createIsSelf" class="flex-between">
				<button class="cancel-button flex1 mr10" @click="cancelMeeting">
					取消会议
				</button>
				<button class="edit-button flex1" @click="editMeeting">
					修改会议
				</button>
			</view>
			<view v-else>
				<button class="cancel-button flex1 mr10" @click="rejectMeeting">
					拒绝会议
				</button>
			</view>
		</view>

		<uni-popup
			ref="popup"
			type="bottom"
			@maskClick="closePopup()"
			catchtouchmove="true"
		>
			<view class="popup-bd">
				<view class="popup-title mt20">
					拒绝会议
					<uni-icons
						type="closeempty"
						size="35rpx"
						color="#666666"
						class="popup-close"
						@click="closePopup()"
					></uni-icons>
				</view>
				<view class="pop-content">
					<reject-meeting
						@onRejectionCancel="onRejectionCancel"
						@onRejectionConfirm="onRejectionConfirm"
						:scheduleId="scheduleId"
					></reject-meeting>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
import RejectMeeting from '../scheduleRejMeeting.vue'
import { cancelSchedule } from '@/apis/calendar'
import { insertSpace } from '@/common/utils.js'

export default {
	components: {
		'reject-meeting': RejectMeeting,
	},
	props: {
		name: {
			type: String,
			value: '',
		},
		scheduleId: {
			type: Number,
			value: 0,
		},
		meetingId: {
			type: Number,
			value: 0,
		},
		weekStr: {
			type: String,
			value: '',
		},
		dateStr: {
			type: String,
			value: '',
		},
		startTime: {
			type: String,
			value: '',
		},
		endTime: {
			type: String,
			value: '',
		},
		createName: {
			type: String,
			value: '',
		},
		meetingCode: {
			type: String,
			value: '',
		},
		createIsSelf: {
			type: Number,
		},
		totalNum: {
			type: Number,
		},
		agreeNum: {
			type: Number,
		},
		refuseNum: {
			type: Number,
		},
		status: {
			type: Number,
		},
	},
	computed: {
		meetingCodeSpace() {
			return insertSpace(this.meetingCode)
		},
	},
	methods: {
		copy() {
			uni.setClipboardData({
				data: this.meetingCode,
				success: function () {
					console.log('success')
				},
			})
		},
		showPopup(e) {
			this.$refs.popup.open()
		},
		// 关闭窗口
		closePopup(e) {
			this.$refs.popup.close()
		},
		joinMeeting() {
			// TODO：加入会议

			wx.navigateToMiniProgram({
				appId: 'wx33fd6cdc62520063',

				path: `pages/sub-preMeeting/join-meeting/join-meeting?m=${this.meetingCode}`,
			})
		},
		cancelMeeting() {
			const scheduleId = this.scheduleId
			const _this = this
			uni.showModal({
				title: '确认是否取消会议？',
				success: function (res) {
					if (res.confirm) {
						cancelSchedule({ scheduleId: scheduleId }).then(
							(res) => {
								if (res.success) {
									_this.successToast(res.message)
								}
							}
						)
					}
				},
			})
		},
		editMeeting() {
			// TODO：跳转编辑
			this.checkDetail()
		},
		rejectMeeting() {
			this.showPopup()
		},
		onRejectionCancel() {
			this.closePopup()
		},
		onRejectionConfirm(message) {
			// TODO：拒绝成功
			this.successToast(message)
			this.closePopup()
		},
		checkDetail() {
			uni.navigateTo({
				url: `/subPackagesLog/pages/workLog/schedule/create?scheduleId=${this.scheduleId}`,
			})
		},
		successToast(title) {
			uni.showToast({
				title,
			})

			this.$emit('reloadList')
		},
	},
}
</script>
<style scoped lang="scss">
.line1 {
	justify-content: space-between;
	flex-direction: row;
	display: flex;
}

.line2 {
}

.reject-color {
	color: #d9001b;
}

.line-box:before {
	content: '';
	/* 必须添加 */
	display: block;
	border-bottom: 2rpx solid #efefef;
}

.flex1 {
	flex: 1;
}

.enter-button {
	background-color: #3a9bff;
	color: #ffffff;
	font-size: 12px;
	border-radius: 40rpx;
}

.cancel-button,
.edit-button {
	border: 2rpx solid #3a9bff;
	color: #3a9bff;
	font-size: 12px;
	background-color: #fff;
	border-radius: 40rpx;
}

.pop-content {
	background-color: #fff;
	height: calc(100vh - 300rpx);
}

.popup-title {
	font-size: 14px;
}

.detail-btn {
	width: 250rpx;
	text-align: right;
}
.accept-text {
	margin-left: 14rpx;
}
</style>
